package com.five.dao.impl.backstage;

import com.five.dao.backstage.CSTongjiDao;
import com.five.entity.backstage.CSTongji;
import com.five.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author:常鹏宇
 * @Description
 * @date:2020/12/5
 */
@Repository
public class CSTongjiDaoImpl implements CSTongjiDao {

    @Override
    public List<Map> selectPType() {
        return DBUtil.queryMap("select * from t_ptype");
    }

    @Override
    public List<Map> tongjiType() {
        return DBUtil.queryMap("select name from t_ptype");
    }

    @Override
    public List<Map> selectTongji(CSTongji csTongji) {
        String sql = "select p.id,p.name,SUM(r.price*r.count) money,year(rdate) year,month(rdate) month,year(now()) now\n" +
                    "from t_ptype p\n" +
                    "left join t_facility f\n" +
                    "on p.id=typeid\n" +
                    "left join t_rukudetail r\n" +
                    "on f.id=ssid\n" +
                    "left join t_ruku\n" +
                    "on rukuid=ruid\n" +
                    "where 1=1 ";
            if(csTongji.getYear()==null || csTongji.getYear()==""){
                sql+= " and year(rdate)=year(now())";
            } else {
                sql+= " and year(rdate)="+csTongji.getYear();
            }
                sql+= " GROUP BY p.name,month\n" +
                    "ORDER BY year,month,id";
        System.out.println(csTongji.getYear());
        List<Map> maps = DBUtil.queryMap(sql);
        return maps;
    }


}
